<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<x:parse xml="${param.xmlstr}" var="xmlData" />

<div class="t_bar2">合作单位信息</div>
<table class="t_css" width="100%" border="0" cellpadding="0" cellspacing="1" id="tblPurchases">
   <thead >
		<tr name="externTr">
			<th class="TblHead" align="center" width="5%">选择</th>
			<th class="TblHead" align="center" width="5%">序号</th>
			<th class="TblHead" align="center" width="90%">合作单位基本情况</th>
		</tr>
	</thead>
			<tbody id="tab">
					<tr style="display:none" align="center" name="externTr">
						<td align="center">&nbsp;<input type="radio" class="radiobutton" name="selPurchases" ></td>
						<td align="center">&nbsp;<span name="purchases|purchase[0]@seq_no" >[index]</span></td>
						<td>
						<table cellpadding="0" class="table01" width="100%" border="0" cellpadding="0" style="*border-bottom: #a1c0dc 1px solid;">
						<tr>
				           <td align="right">单位名称：</td>
				           <td colspan="3" align="left"><input name="purchases|purchase[0]|org_name" label="单位名称" type="text"  class="input_css required" style="width: 650px;" maxlength="100" value="" /></td>
		                </tr>
						<tr>
							<td align="right">单位地址：</td>
							<td align="left" colspan="3" ><input name="purchases|purchase[0]|address" label="单位地址" type="text"  class="input_css required"  maxlength="100" style="width: 650px;" /></td>
							<!-- <td align="right">单位资质：</td>
							<td align="left"><input name="purchases|purchase[0]|org_aptitude" label="单位资质" type="text" required class="input_css required"  maxlength="100" value="" /></td> -->
						
						</tr>
						<tr>
							<td width="14%" align="right">注册类型：</td>
							<td width="38%" align="left" colspan="1" align="left">
							 <cpt:tree key="nature_type2" cacheable="false" className="hn_iuput_kuang gray" readonly="true" value="" label="注册类型"
							  id="nature[index]" showPattern="current" shieldPattern="0" topCheckbox="false" onClick="initTreeValueForNature" /> 
							 <input type="hidden" id="nature[index]_code" name="purchases|purchase[0]|nature_code" class="required" label="注册类型" value="" /> 
							<input type="hidden" id="nature[index]_name" name="purchases|purchase[0]|nature_name" value="" /></td>
							<td align="right">组织机构代码：</td>
							<td align="left"><input name="purchases|purchase[0]|org_no"   id="nature[index]_org_no" label="组织机构代码" type="text" class="input_css required orgCard" maxlength="20" value="" /></td>
						</tr>
						<!-- <tr>
							<td align="right" nowrap>承担任务：</td>
							<td align="left">
							<input name="purchases|purchase[0]|task" label="承担任务" type="text" class="input_css required"  maxlength="50" value="" /></td>
							<td align="right" nowrap>工作量占比%：</td>
							<td align="left"><input name="purchases|purchase[0]|money_pre" label="工作量占比" type="text" class="input_css required" style="text-align: right" onfocus="InitInput.setNumber(this,9,4,2)" maxlength="20" value="" /></td>
						</tr> -->
						<tr>
							<td align="right">联系人：</td>
							<td align="left">
							<input name="purchases|purchase[0]|lxr_name" label="联系人" type="text" class="input_css required" maxlength="20" value="" /></td>
							<td align="right">联系电话：</td>
							<td align="left"><input name="purchases|purchase[0]|lxr_tel" label="联系电话" type="text" class="input_css required" maxlength="20" value="" /></td>
						</tr>
						</table>
						</td>
					</tr>
					
					<c:set value="0" var="index" scope="page"/>
					<x:forEach select="$xmlData/data/purchases/purchase" var="purchase">
					
					<c:choose>
						<c:when test="${index<10}" ><c:set value="0" var="flag" scope="page"/></c:when>
						<c:otherwise><c:set value="" var="flag" scope="page"/></c:otherwise>
					</c:choose>
					<tr align="center" name="externTr">
						<td align="center">&nbsp;<input type="radio" class="radiobutton" name="selPurchases" ></td>
						<td align="center">&nbsp;<span name="purchases/purchase[${flag}${index}]@seq_no" ><x:out select="$purchase/@seq_no"/></span></td>
						<td>
						<table cellpadding="0" class="table01" width="100%" border="0" cellpadding="0" style="*border-bottom: #a1c0dc 1px solid;">
						<tr>
				           <td align="right">单位名称：</td>
				           <td colspan="3" align="left"><input name="purchases/purchase[${flag}${index}]/org_name" label="单位名称" type="text"  class="input_css required" style="width: 650px;" maxlength="100" value="<x:out select="$purchase/org_name" />" /></td>
		                </tr>
						<tr>
							<td align="right">单位地址：</td>
							<td align="left" colspan="3"><input name="purchases/purchase[${flag}${index}]/address" label="单位地址" type="text" style="width: 650px;" class="input_css required"  maxlength="100" value="<x:out select="$purchase/address" />" /></td>
							<%-- <td align="right">单位资质：</td>
							<td align="left"><input name="purchases/purchase[${flag}${index}]/org_aptitude" label="单位资质" type="text" required class="input_css required"  maxlength="100" value="<x:out select="$purchase/org_aptitude" />" /></td> --%>
						</tr>
						<tr>
							<td width="14%" align="right">注册类型：</td>
							<td width="38%" align="left" colspan="1" >
							<c:set var="nature">{'id':'<x:out select="$purchase/nature_code" />','name':'<x:out select="$purchase/nature_name" />'}</c:set>
							 <cpt:tree key="nature_type2" cacheable="false" className="hn_iuput_kuang gray" readonly="true" value="${nature}" label="注册类型"
							  id="nature${flag}${index}"  showPattern="current" shieldPattern="0" topCheckbox="false" onClick="initTreeValueForNature" /> 
							 <input type="hidden" id="nature${flag}${index}_code" name="purchases/purchase[${flag}${index}]/nature_code" class="required" label="注册类型" value="<x:out select="$purchase/nature_code" />" /> 
							<input type="hidden" id="nature${flag}${index}_name" name="purchases/purchase[${flag}${index}]/nature_name" value="<x:out select="$purchase/nature_name" />" /></td>
							<td align="right">组织机构代码：</td>
							<td align="left"><input name="purchases/purchase[${flag}${index}]/org_no"  id="nature${flag}${index}_org_no"  label="组织机构代码" type="text" class="input_css required orgCard" maxlength="20" value="<x:out select="$purchase/org_no" />" /></td>
						</tr>
						<%-- <tr>
							<td align="right" nowrap>承担任务：</td>
							<td align="left">
							<input name="purchases/purchase[${flag}${index}]/task" label="承担任务" type="text" class="input_css required"  maxlength="50" value="<x:out select="$purchase/task" />" /></td>
							<td align="right" nowrap>工作量占比%：</td>
							<td align="left"><input name="purchases/purchase[${flag}${index}]/money_pre" label="工作量占比" type="text" class="input_css required"  style="text-align: right" onfocus="InitInput.setNumber(this,9,4,2)" maxlength="20" value="<x:out select="$purchase/money_pre" />" /></td>
						</tr> --%>
						<tr>
							<td align="right">联系人：</td>
							<td align="left">
							<input name="purchases/purchase[${flag}${index}]/lxr_name" label="联系人" type="text" class="input_css required" maxlength="20" value="<x:out select="$purchase/lxr_name" />" /></td>
							<td align="right">联系电话：</td>
							<td align="left"><input name="purchases/purchase[${flag}${index}]/lxr_tel" label="联系电话" type="text" class="input_css required" maxlength="20" value="<x:out select="$purchase/lxr_tel" />" /></td>
						</tr>
						</table>
						</td>
					</tr>
					<c:set value="${index+1}" var="index" scope="page"/>
					</x:forEach>
				</tbody>
					</table>
					<table width="98%" align="center">
					<tr ><td>
					<input class="button" name="cmdAddbefore" type=button value="添加" onclick="if(checkTabLimit('tblPurchases',99,'合作单位基本情况最多只能填写99条')){addNewRow('tblPurchases');}try{top.resizeFrame();}catch(e){};">
					<input class="button" name="cmdMovePrev" type=button value="上移" onclick="movePrev('tblPurchases','selPurchases')">
					<input class="button" name="cmdMoveNext" type=button value="下移" onclick="moveNext('tblPurchases','selPurchases')">
					<input class="button" name="cmddel" type=button  value="删除" onclick="deleteSelectedRow('tblPurchases','合作单位基本情况');">
					</td></tr>
					</table>	
					
<script type="text/javascript">

$(function(){
	
	$("#tblPurchases").find(":input[id*=_code]").each(function(i, obj){
		var org_no=obj.id.replace("_code","_org_no");
		
		if(obj.value=="M99"){
			$("#" + org_no).val("");
			$("#" + org_no).attr("disabled",true);
			$("#" + org_no).addClass("gray");	
			$("#" + org_no).removeClass("required");	
		}else{
			$("#" + org_no).attr("disabled",false);
			$("#" + org_no).addClass("required");
			$("#" + org_no).removeClass("gray");	
		}
	});
	
	
	
});


		/**
		* 选择树设置隐藏域值 public.js中原函数不适用
		*/
		function initTreeValueForNature(treeId, treeNode) {
		 
		if ((treeNode && treeNode.isParent)) {
			scmWarn("请选择具体的"+$("#" + treeId).attr("label"));
			$("#" + treeId).val("");
			$("#" + treeId).parents("td").find("[name$='" + treeId + "_code'],[id$='" + treeId+ "_code']").val("");
			$("#" + treeId).parents("td").find("[name$='" + treeId + "_value'],[id$='" + treeId+ "_value']").val("");
			$("#" + treeId).parents("td").find("[name$='" + treeId + "_name'],[id$='" + treeId+ "_name']").val("");
			return false;
		}
		
		if (!(treeNode && (treeNode.level > 0 || !treeNode.isParent))) {
			scmWarn($("#" + treeId).attr("label")+ messageTip.researchAreaInvalidDisciplineCode);
			if (treeNode.level == 0) {
				$("#" + treeId).val("");
				$("#" + treeId).parents("td").find("[name$='" + treeId + "_code'],[id$='" + treeId+ "_code']").val("");
				$("#" + treeId).parents("td").find("[name$='" + treeId + "_value'],[id$='" + treeId+ "_value']").val("");
				$("#" + treeId).parents("td").find("[name$='" + treeId + "_name'],[id$='" + treeId+ "_name']").val("");
			}
			return false;
		}
		
		var str = treeNode.name;
		var obj = treeNode.parentNode;
		while (obj != null) {
			obj = obj.parentNode;
		}
		
		if(treeNode.id=="M99"){
			$("#" + treeId+"_org_no").val("");
			$("#" + treeId+"_org_no").attr("disabled",true);
			$("#" + treeId+"_org_no").addClass("gray");	
			$("#" + treeId+"_org_no").removeClass("required");	
		}else{
			$("#" + treeId+"_org_no").attr("disabled",false);
			$("#" + treeId+"_org_no").addClass("required");
			$("#" + treeId+"_org_no").removeClass("gray");	
		}
		
		
		$("#" + treeId).parents("td").find("[name$='" + treeId + "_code'],[id$='" + treeId + "_code']").val(treeNode.id);
		$("#" + treeId).parents("td").find("[name$='" + treeId + "_value'],[id$='" + treeId + "_value']").val(treeNode.id);
		$("#" + treeId).parents("td").find("[name$='" + treeId + "_name'],[id$='" + treeId + "_name']").val(str);
	 
		} 
		
	
	
	$(function(){
		$("#orgInfo tr:even").addClass("li_1");
	    $("#orgInfo tr:odd").addClass("li_2");
	    $("#orgInfo2 tr:even").addClass("li_1");
	    $("#orgInfo2 tr:odd").addClass("li_2");
	    $("#orgInfo3 tr:even").addClass("li_1");
	    $("#orgInfo3 tr:odd").addClass("li_2");
	    $("#fmzl tr:even").addClass("li_1");
	    $("#fmzl tr:odd").addClass("li_2");
	    $("#tblAttendOrg tr:even").addClass("li_1");
	    $("#tblAttendOrg tr:odd").addClass("li_2");
	});


		/**
		 * 增加一行
		 * @param tableId表格Id
		 * @param radioId
		 * @param nNewRowPosition
		 * @param startRowIndex
		 */
		function addNewRowDeal(table)
		{
			if(table.attr("id")=='tblPurchases'){
				var maxLinNum=table.find("tr[name='externTr']").length-2;;//获得行数，减去表头和隐藏行
				var lineNum=""+(maxLinNum+1);
				
				var addHtml=table.find("tr[name='externTr']")[1].innerHTML;//获得隐藏行的html,查找第二行
				addHtml=addHtml.replace(/\[index\]/g,lineNum);
				lineNum = (parseInt(lineNum, 10)-1).toString();//2011.12.13 行下标比行号小1(隐藏行下标[0]，第一行下标[00])
				if (lineNum.length==1)//如果是个位数，前面补0
					lineNum="0"+lineNum;
				addHtml=addHtml.replace(/\[0\]/g,"["+lineNum+"]");//替换html中行号
				addHtml=addHtml.replace(/\|/g,"/");//替换html中节点/的代替符"|"
				
				table.append("<tr name='externTr'>"+addHtml+"</tr>");//将html增加到最后
			}
			else if (table.attr("id") == "tblMileStones")
			{
				var maxLinNum=table.find("tr").length-4;//获得行数，减去表头和隐藏行
				var lineNum=""+(maxLinNum+2);
				var addHtml=table.find("tr")[2].innerHTML;//获得隐藏行的html,查找第二行
				addHtml=addHtml.replace(/\[index\]/g,lineNum);
				lineNum = (parseInt(lineNum, 10)-1).toString();//2011.12.13 行下标比行号小1(隐藏行下标[0]，第一行下标[00])
				if (lineNum.length==1)//如果是个位数，前面补0
				lineNum="0"+lineNum;
				addHtml=addHtml.replace(/\[0\]/g,"["+lineNum+"]");//替换html中行号
				addHtml=addHtml.replace(/\|/g,"/");//替换html中节点/的代替符"|"
				table.append("<tr>"+addHtml+"</tr>");//将html增加到最后		
			}
			else
			{
				var maxLinNum=table.find("tr").length-2;;//获得行数，减去表头和隐藏行
				var lineNum=""+(maxLinNum+1);
				
				var addHtml=table.find("tr")[1].innerHTML;//获得隐藏行的html,查找第二行
				addHtml=addHtml.replace(/\[index\]/g,lineNum);
				lineNum = (parseInt(lineNum, 10)-1).toString();//2011.12.13 行下标比行号小1(隐藏行下标[0]，第一行下标[00])
				if (lineNum.length==1)//如果是个位数，前面补0
					lineNum="0"+lineNum;
				addHtml=addHtml.replace(/\[0\]/g,"["+lineNum+"]");//替换html中行号
				addHtml=addHtml.replace(/\|/g,"/");//替换html中节点/的代替符"|"
				
				table.append("<tr >"+addHtml+"</tr>");//将html增加到最后
			}
		}
	
	
</script>
					